package org.aspectsense.middleware.adaptation;

import java.awt.Point;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.StringTokenizer;

import org.aspectsense.middleware.ComponentContainer;
import org.aspectsense.middleware.adaptation.AdaptationManager.EVENT_TYPE;

public class BigraphComponentNode
{
	private HashMap <String, LinkedList<BigraphComponentNode>> children;
	private ComponentContainer cc;
	private BigraphComponentNode parent;
	private LinkedList <BigraphServiceNode> connections;
	private Point coordinates;
	private String providedService;
	

	public BigraphComponentNode (ComponentContainer cc, BigraphComponentNode parent, String s)
	{
		children = new HashMap<String, LinkedList<BigraphComponentNode>> ();
		connections = new LinkedList <BigraphServiceNode> ();
		this.cc = cc;
		this.parent = parent;
		this.coordinates = new Point ();
		this.providedService = s;
	}
	
	
	public String getProvidedService ()
	{
		return this.providedService;
	}
	
	public String getContainerName() {
		
		return this.cc.getContainerName();
	}

	public ComponentContainer getContainer() {
		
		return this.cc;
	}


	public String getShortComponentName() {
		String name="";
		StringTokenizer tok = new StringTokenizer (this.cc.getProviderName(),".");
		while (tok.hasMoreTokens())
		{
			name = tok.nextToken();
		}
		return name;
	}
	
	
	public boolean isRoot ()
	{
		if (this.parent==null)
			return true;
		else
			return false;
	}


	public void addChildren(String s, BigraphComponentNode child)
	{
		LinkedList <BigraphComponentNode> chl = children.get(s);
		if (chl==null)
			chl = new LinkedList <BigraphComponentNode> ();
		chl.add(child);
		this.children.put(s, chl);
	
		
	}


	public BigraphComponentNode getParent() {
		// TODO Auto-generated method stub
		return this.parent;
	}


	public LinkedList<BigraphComponentNode> getChildren(String s) {
		// TODO Auto-generated method stub
		return children.get(s);
	}




	public void addConnection(BigraphServiceNode snode) {
		connections.add(snode);
		
	}




	public void setCoordinates(Point point) {
		this.coordinates = point;
		
	}




	public Point getCoordinates() {
		// TODO Auto-generated method stub
		return this.coordinates;
	}




	public LinkedList <BigraphServiceNode>  getConnections() {
		return this.connections;
		
	}


	public String getProvidedServiceShortName() {
		
		StringTokenizer tkz = new StringTokenizer (this.providedService, ".");
		String name="";
		while (tkz.hasMoreElements())
		{
			name = (String) tkz.nextElement();
		}
		return name;
	}
	
	
}
